package accidence;

import org.junit.Test;

import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * 提取不重复的整数
 *
 * @author sdm
 * @version 1.0
 * @date 2023/3/18 12:54
 */
public class HJ9 {


    @Test
    public void MyHJ9() {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别

        String str = in.nextLine();

        // 反转
        StringBuilder sb = new StringBuilder(str);
        String s = sb.reverse().toString();

        // 除0
        while (s.startsWith("0")) {
            s = s.substring(1);
        }
        // 去重
        // 方式一：利用HashSet中只有key且可key值不重复特性；调用set.add() 方法时，key如果已存在，就不加入，key不存在，才加入
        // 方式二：set.contains()判断去重
        char[] c = s.toCharArray();
        HashSet set = new HashSet();
        StringBuilder res = new StringBuilder();
        for(int i = 0; i < c.length; i++){
            if(set.add(c[i])){
                res.append(c[i]);
            }
        }
        System.out.println(res);
    }

    @Test
    public void HJ91(){
        Scanner in = new Scanner(System.in);
        LinkedHashSet<Integer> set = new LinkedHashSet<>();  // 保持顺序使用LinkedHashSet
        for (int num = in.nextInt(); num > 0; num /= 10) {  // num /= 10 就是num = num / 10
            set.add(num % 10);  // set.add方法的key不重复
        }
        set.forEach(System.out::println);

    }

    @Test
    public void HJ92(){
        Scanner scanner = new Scanner(System.in);
        String string = scanner.nextLine();
        Set<Character> set = new LinkedHashSet<>();
        for (int i = string.length() - 1; i >= 0; i--) {
            set.add(string.charAt(i));
        }
        for (Character character : set) {
            System.out.print(character);
        }

    }



}
